// 任务类型枚举
export type TaskType = 'detection' | 'classification' | 'segmentation' | 'registration' | 'reconstruction'

// 任务状态枚举
export type TaskStatus = 'idle' | 'running' | 'completed' | 'error' | 'cancelled' | 'pending'

// 任务接口
export interface Task {
    id: string
    name: string
    type: TaskType
    description: string
    config: TaskConfig
    status: TaskStatus
    datasetId: string
    createdAt: Date
    updatedAt: Date
    estimatedDuration?: number // 预估执行时间（秒）
    priority?: number // 任务优先级
}

export interface TaskConfig {
    parameters: Record<string, unknown>
    modelEndpoint?: string
    preprocessing?: PreprocessingConfig
    postprocessing?: PostprocessingConfig
    validation?: ValidationConfig
}

export interface PreprocessingConfig {
    normalize?: boolean
    resize?: {
        width: number
        height: number
        depth?: number
    }
    windowLevel?: {
        center: number
        width: number
    }
    crop?: {
        x: number
        y: number
        width: number
        height: number
    }
    rotation?: number
    flip?: 'horizontal' | 'vertical' | 'both'
}

export interface PostprocessingConfig {
    smoothing?: boolean
    threshold?: number
    morphology?: {
        operation: 'opening' | 'closing' | 'erosion' | 'dilation'
        kernelSize: number
    }
}

export interface ValidationConfig {
    crossValidation?: {
        folds: number
        shuffle: boolean
    }
    testSplit?: number
    metrics: string[]
}

export interface TaskResult {
    id: string
    taskId: string
    status: 'success' | 'error'
    data?: TaskResultData
    error?: string
    metrics?: TaskMetrics
    executionTime: number // 实际执行时间（秒）
    createdAt: Date
}

export interface TaskResultData {
    detections?: Detection[]
    classifications?: Classification[]
    segmentations?: Segmentation[]
    [key: string]: unknown
}

export interface Detection {
    id: string
    bbox: [number, number, number, number] // [x, y, width, height]
    confidence: number
    class: string
    slice?: number // 3D数据中的切片位置
}

export interface Classification {
    class: string
    confidence: number
    probabilities: Record<string, number>
}

export interface Segmentation {
    mask: ArrayBuffer | string // 分割掩码数据或URL
    classes: string[]
    colors: Record<string, string> // 类别颜色映射
}

export interface TaskMetrics {
    accuracy?: number
    precision?: number
    recall?: number
    f1Score?: number
    iou?: number // Intersection over Union
    dice?: number // Dice coefficient
    [key: string]: number | undefined
}

export interface TaskParams {
    imageIds?: string[]
    modelVersion?: string
    batchSize?: number
    [key: string]: unknown
}

export interface TaskStatusInfo {
    id: string
    status: TaskStatus
    progress?: number
    message?: string
    currentStep?: string
    totalSteps?: number
    startTime?: Date
    estimatedCompletion?: Date
}

// 任务创建请求
export interface CreateTaskRequest {
    name: string
    type: TaskType
    description: string
    datasetId: string
    config: TaskConfig
    priority?: number
}

// 任务更新请求
export interface UpdateTaskRequest {
    name?: string
    description?: string
    config?: Partial<TaskConfig>
    priority?: number
}